/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package uit.qlks.from;

import java.rmi.Naming;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.WebRowSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import uit.ejb.dto.HoaDonDTO;
import uit.qlks.baocao.BaoCao;
import uit.qlks.controller.hoadon.HoaDonController;
import uit.qlks.controller.khachhang.KhachHangController;
import uit.qlks.controller.loaidichvu.LoaiDichVuController;
import uit.qlks.controller.loaiphong.LoaiPhongCotroller;
import uit.qlks.controller.phieuthue.PhieuThueController;
import uit.qlks.controller.phieuthuedv.PhieuThueDVController;
import uit.qlks.controller.phong.PhongController;

/**
 *
 * @author HUTA
 */
public class frmHoaDon extends javax.swing.JFrame {

    /**
     * Creates new form frmHoaDon
     */

    public String MaPhieuThue = "5";
    public String MaKH  = "21";
    public String MaPhong = "11";
    public HoaDonDTO HD;
    public int SoNgay = 3;
    private Long  TienPhong;
    private Long TienDV ;
    int preframe = 0;

    public frmHoaDon() {
        initComponents();
        HD = new HoaDonDTO();
        TienDV = Long.parseLong("0");
        TienPhong = Long.parseLong("0");
        jltiendvcu.setVisible(false);
        jltienphongcu.setVisible(false);
        txtTienDVcu.setVisible(false);
        txttienphongcu.setVisible(false);
    }
    
    private void LayThongTinKhachHang(String MaKh)
    {
        try{
            WebRowSet wrs = KhachHangController.khachHang_GetById(MaKh);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy");
            if(wrs.next())
            {
                this.txtMaKH.setText("KH"+wrs.getString("MaKH").toString());
                this.txtHoTen.setText(wrs.getString("TenKH").toString());
                this.txtGioiTinh.setText(wrs.getString("GioiTinh").toString());
                this.txtDiaChi.setText(wrs.getString("DiaChi").toString());
                Date d = wrs.getDate("NgaySinh");
                this.txtNgaySinh.setText(sdf.format(d));
                this.txtSDT.setText(wrs.getString("SDT").toString());
                this.txtCMND.setText(wrs.getString("CMND").toString());
                this.txtQuocTich.setText(wrs.getString("QuocTich").toString());
            }
        }
        catch(Exception e)
        {
              JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    
    private void LayPhieuThue(String MaPhieuThue, int SoNgay)
    {
        try{
            WebRowSet wrs = PhieuThueController.phieuThue_GetById(MaPhieuThue);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy");
            if(wrs.next())
            {
                Date d = wrs.getDate("NgayThue");
                this.txtNgayDen.setText(sdf.format(d));
                d = wrs.getDate("NgayDi");
                this.txtNgayDi.setText(sdf.format(d));
                this.txtSoNgay.setText(String.valueOf(SoNgay));
            }
        }
        catch(Exception e)
        {
           JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE); 
        }
    }
    private void LayDichVu(String MaPhieuThue)
    {
        try{
            DefaultTableModel model = (DefaultTableModel) this.jtDSDVThue.getModel();
            model.getDataVector().removeAllElements();

            WebRowSet wrs = PhieuThueDVController.phieuThueDV_GetByTop("", " MaPhieuThue = '"+MaPhieuThue+"' ", "");
            Vector rowData;
            TienDV = Long.parseLong("0");
            if(wrs!=null)
            {
                while(wrs.next())
                {
                    rowData = new Vector();
                    rowData.add(wrs.getRow());
                    String Id = wrs.getString("MaDV");
                    WebRowSet rs = LoaiDichVuController.loaiDichVu_GetById(Id);
                    rs.next();
                    rowData.add(rs.getString("TenDV"));
                    rowData.add(wrs.getString("SoLuong"));
                    rowData.add(rs.getString("Gia"));
                    
                    model.addRow(rowData);
                    TienDV += Long.parseLong(wrs.getString("SoLuong").toString().replace(".0", "")) *Long.parseLong(rs.getString("Gia").toString().replace(".0", ""));
                }
            }
            this.txtTienDV.setText(Format_Price(String.valueOf(TienDV)));
        }
        catch(Exception e)
        {
           JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    private void LayPhongThue(String MaPhong, int SoNgay)
    {
        try{
            WebRowSet wrs = PhongController.phong_GetById(MaPhong);
            if(wrs.next())
            {
                // Lấy thông tin phòng
                this.txtMaPhong.setText("MP"+MaPhong);
                this.txtTenPhong.setText(wrs.getString("TenPhong"));
                String MaLoaiPhong = wrs.getString("MaLoaiPhong");
                WebRowSet rs = LoaiPhongCotroller.loaiPhong_GetById(MaLoaiPhong);
                if(rs.next())
                {
                    //Lấy tên loại phòng.
                    this.txtLoaiPhong.setText(rs.getString("TenLoaiPhong").toString());
                    TienPhong = (SoNgay)* Long.parseLong(rs.getString("Gia").toString().replace(".0",""));
                    this.txtTienPhong.setText(Format_Price(String.valueOf(TienPhong)));                    
                }
            }
//            return 0;
        }
        catch(Exception e)
        {
          JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtHoTen = new javax.swing.JTextField();
        txtMaKH = new javax.swing.JTextField();
        txtNgaySinh = new javax.swing.JTextField();
        txtGioiTinh = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        txtSDT = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtDiaChi = new javax.swing.JTextField();
        txtCMND = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtQuocTich = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtDSDVThue = new javax.swing.JTable();
        txtTienDV = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jltiendvcu = new javax.swing.JLabel();
        txtTienDVcu = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        txtMaPhong = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txtTenPhong = new javax.swing.JTextField();
        txtLoaiPhong = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtSoNgay = new javax.swing.JTextField();
        txtNgayDen = new javax.swing.JTextField();
        txtNgayDi = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtTienPhong = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jltienphongcu = new javax.swing.JLabel();
        txttienphongcu = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        txtTongTien = new javax.swing.JTextField();
        btnPrint = new javax.swing.JButton();
        btnLapHoaDon = new javax.swing.JButton();
        btHuyhoadon = new javax.swing.JButton();
        lbstatus = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Hóa Đơn");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin khách hàng"));

        jPanel4.setOpaque(false);

        jLabel1.setText("Mã Khách Hàng:");

        jLabel2.setText("Họ tên:");

        jLabel3.setText("Ngày sinh:");

        jLabel4.setText("Giới tính:");

        txtHoTen.setEditable(false);

        txtMaKH.setEditable(false);

        txtNgaySinh.setEditable(false);

        txtGioiTinh.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtGioiTinh)
                    .addComponent(txtNgaySinh)
                    .addComponent(txtHoTen)
                    .addComponent(txtMaKH, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtMaKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel5.setOpaque(false);

        txtSDT.setEditable(false);

        jLabel7.setText("SĐT:");

        jLabel8.setText("Địa chỉ:");

        txtDiaChi.setEditable(false);

        txtCMND.setEditable(false);

        jLabel6.setText("CMND:");

        jLabel9.setText("Quốc tịch:");

        txtQuocTich.setEditable(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel7))
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCMND, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtQuocTich, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtQuocTich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(97, 97, 97)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(97, 97, 97)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(161, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Dịch vụ đã thuê"));

        jtDSDVThue.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Tên DV", "Số lượng", "Giá"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtDSDVThue.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jtDSDVThue);

        txtTienDV.setEditable(false);

        jLabel10.setText("Tổng tiền dịch vụ:");

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Paper-Money.png"))); // NOI18N

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jltiendvcu.setText("Tổng tiền DV cũ:");

        txtTienDVcu.setEditable(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 564, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(18, 18, 18)
                        .addComponent(txtTienDV, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jltiendvcu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtTienDVcu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(72, 72, 72))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jltiendvcu)
                            .addComponent(txtTienDVcu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(txtTienDV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Phòng thuê"));

        jLabel13.setText("Mã phòng:");

        txtMaPhong.setEditable(false);

        jLabel14.setText("Tên phòng:");

        jLabel15.setText("Loại phòng:");

        txtTenPhong.setEditable(false);

        txtLoaiPhong.setEditable(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel13)
                    .addComponent(jLabel15))
                .addGap(25, 25, 25)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtLoaiPhong, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                    .addComponent(txtMaPhong, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                    .addComponent(txtTenPhong, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtMaPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtTenPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel16.setText("Ngày đến:");

        jLabel17.setText("Ngày đi:");

        jLabel18.setText("Số ngày:");

        txtSoNgay.setEditable(false);

        txtNgayDen.setEditable(false);

        txtNgayDi.setEditable(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addGap(18, 18, 18)
                        .addComponent(txtNgayDen, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(jLabel17))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNgayDi, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                            .addComponent(txtSoNgay, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txtNgayDen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(txtNgayDi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(txtSoNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel20.setText("Tổng tiền phòng:");

        txtTienPhong.setEditable(false);

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jltienphongcu.setText("Tiiền phòng cũ:");

        txttienphongcu.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jltienphongcu)
                    .addComponent(jLabel20))
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txttienphongcu)
                    .addComponent(txtTienPhong, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txttienphongcu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jltienphongcu))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTienPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addContainerGap(18, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
        );

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel5.setText("Thông Tin Hóa Đơn");

        jLabel22.setText("Tổng tiền:");

        txtTongTien.setEditable(false);
        txtTongTien.setForeground(new java.awt.Color(255, 4, 4));

        btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer.png"))); // NOI18N
        btnPrint.setText("Printer");
        btnPrint.setBorder(null);
        btnPrint.setContentAreaFilled(false);
        btnPrint.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer2.png"))); // NOI18N
        btnPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintActionPerformed(evt);
            }
        });

        btnLapHoaDon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit.png"))); // NOI18N
        btnLapHoaDon.setText("Lập Hóa Đơn");
        btnLapHoaDon.setBorder(null);
        btnLapHoaDon.setContentAreaFilled(false);
        btnLapHoaDon.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit2.png"))); // NOI18N
        btnLapHoaDon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLapHoaDonActionPerformed(evt);
            }
        });

        btHuyhoadon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete.png"))); // NOI18N
        btHuyhoadon.setText("Hủy Hóa Đơn");
        btHuyhoadon.setBorder(null);
        btHuyhoadon.setContentAreaFilled(false);
        btHuyhoadon.setEnabled(false);
        btHuyhoadon.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        btHuyhoadon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyhoadonActionPerformed(evt);
            }
        });

        lbstatus.setFont(new java.awt.Font("Times New Roman", 1, 14));
        lbstatus.setForeground(new java.awt.Color(255, 0, 0));
        lbstatus.setText("Đã Thanh Toán");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(382, 382, 382)
                .addComponent(jLabel5))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(106, 106, 106)
                .addComponent(btHuyhoadon)
                .addGap(58, 58, 58)
                .addComponent(btnLapHoaDon)
                .addGap(79, 79, 79)
                .addComponent(btnPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 171, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addGap(31, 31, 31)
                        .addComponent(txtTongTien, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(92, 92, 92))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lbstatus)
                        .addGap(112, 112, 112))))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(txtTongTien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbstatus))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnLapHoaDon, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btHuyhoadon))))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-975)/2, (screenSize.height-664)/2, 975, 664);
    }// </editor-fold>//GEN-END:initComponents

private void btnLapHoaDonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLapHoaDonActionPerformed
// TODO add your handling code here:
    try{

        //Lay gio he thong
        Date todayD=new Date(System.currentTimeMillis()); 
        SimpleDateFormat dayFormat= new SimpleDateFormat("MM/dd/yyyy"); 
        String today=dayFormat.format(todayD.getTime());       
        HoaDonDTO hd = new HoaDonDTO();
        hd.setMaHD("");
        hd.setMaPhieuThue(this.MaPhieuThue);
        hd.setTongTien(String.valueOf(TienPhong + TienDV));
        hd.setNgayLap(today);
        hd.setTienDV(String.valueOf(TienDV));

        if(this.btnLapHoaDon.getText().equals("Lập hóa đơn")) //Chưa tồn tại hóa đơn của phiếu thuê có MaPhieuThue trong bảng HoaDon
        {
            if(JOptionPane.showConfirmDialog(this, "Bạn có muốn lập hoa đơn không ?", "Question",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
            {
                if(HoaDonController.hoaDon_Insert(hd))
                {
                    //lay ma hoa don
                    ResultSet rs = HoaDonController.hoaDon_GetByTop("", " MaPhieuThue = '"+hd.getMaPhieuThue()+"' ", "");
                    rs.next();
                    HD.setMaHD(rs.getString("MaHD"));
                    JOptionPane.showMessageDialog(this, "Lập hóa đơn thành công !");
                    btnLapHoaDon.setEnabled(false);
                    btHuyhoadon.setEnabled(true);
                    lbstatus.setVisible(true);
                }
            //set lai tinh trang phong
            ResultSet rs =  PhieuThueController.phieuThue_GetByTop("", " MaPhong = '"+MaPhong+"' ", "");
            ResultSet rshd;
            try 
            {//neu tat ca phieu thue phong nay da lap hoa don thi set lai phong  = 1
                int i = 0;
                while(rs.next())
                {
                    rshd = HoaDonController.hoaDon_GetByTop("", " MaPhieuThue = '"+rs.getString("MaPhieuThue") +"'", "");
                    if(!rshd.next()) 
                    {
                        i = 1;
                        break;
                    }
                }
                if(i == 0)//Neu phong dat truoc do khong co ai thue thi set lai phong trong
                {
                    PhongController.phong_UpdateStatus(MaPhong, "1");
                }
            }
            catch(Exception e){}
        }  
    }
    else
    {

        hd.setMaHD(HD.getMaHD());
        if(HoaDonController.hoaDon_Update(hd))
        {
            JOptionPane.showMessageDialog(this, "Cập nhật hóa đơn thành công !");
        }
    }
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_btnLapHoaDonActionPerformed

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
// TODO add your handling code here:
    this.LayThongTinKhachHang(MaKH);
    this.LayDichVu(MaPhieuThue);
    this.LayPhongThue(MaPhong, SoNgay);
    this.LayPhieuThue(MaPhieuThue, SoNgay);
    txtTongTien.setText(Format_Price(String.valueOf(TienPhong + TienDV)));
        if(!"".equals(HD.getMaHD()))
        {
            btHuyhoadon.setEnabled(true);
            btnLapHoaDon.setEnabled(false);
            lbstatus.setVisible(true);
        }
        else
        {
            this.btnLapHoaDon.setText("Lập hóa đơn");
            btHuyhoadon.setEnabled(false);
            lbstatus.setVisible(false);
        }
}//GEN-LAST:event_formWindowOpened

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

    if(preframe == 0)
    {
        frmPhieuThue._frm.setVisible(true);
        frmPhieuThue._frm.setFocusable(true);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    else
        if(preframe == 1)
        {
            frmTraCuu._frmtc.setVisible(true);
            frmTraCuu._frmtc.setFocusable(true);
        }
    // TODO add your handling code here:
}//GEN-LAST:event_formWindowClosed

private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed
    try {
            // TODO add your handling code here:
            String html ="";//= "<meta http-equiv=Content-Type content='text/html; charset=utf8'>";
            //html += "<LEFT>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</BR>----------Ðộc lập - Tự do - Hạnh phúc-----------</LEFT>";
            html += "<CENTER><h2>HÓA ĐƠN THANH TOÁN</h2>"; 
            html += "<p align=\"left\" style=\"margin-left : 300\"><b>Thông Tin Khách Hàng:</b></p>";
            html += "<p align=\"left\" style=\"margin-left : 450\">";
            html += "<table> <tr><td>Mã Khách Hàng:  "+txtMaKH.getText()+"</td><td>   CMND:  "+txtCMND.getText()+"</td></tr>";
            html += "<tr><td>Họ Tên:  "+txtHoTen.getText()+"</td><td>   Địa Chỉ:  "+txtDiaChi.getText()+"</td></tr>";
            html += "<tr><td>Ngày Sinh:  "+txtNgaySinh.getText()+"</td><td>   Điện Thoại:  "+txtSDT.getText()+"</td></tr>";
            html += "<tr><td>Giới Tính:  "+txtGioiTinh.getText()+"</td><td>   Quốc Tịch:  "+txtQuocTich.getText()+"</td></tr>";
            html +=" </table></p>";
            html += "<p align=\"left\" style=\"margin-left : 300\"><b>Thông Tin Thuê Phòng:</b></p>";
            html += "<p align=\"left\" style=\"margin-left : 450\">";
            html += "<table> <tr><td>Mã Phòng:  "+txtMaPhong.getText()+"</td><td>   Ngày Đến:  "+txtNgayDen.getText()+"</td></tr>";
            html += "<tr><td>Tên Phòng:  "+txtTenPhong.getText()+"</td><td>   Ngày Đi:  "+txtNgayDi.getText()+"</td></tr>";
            html += "<tr><td>Loại Phòng:  "+txtLoaiPhong.getText()+"</td><td>   Số Ngày:  "+txtSoNgay.getText()+"</td></tr>";
            html +=" </table>";
            html += "<p align=\"left\" style=\"margin-left : 300\"><b>Thông Tin Dịch Vụ:</b></p>";
            String footer ="";
            footer += "<b>Tiền phòng : </b>" + txtTienPhong.getText() + "<br>";
            footer += "<b>Tiền dịch vụ : </b>" + txtTienDV.getText() + "<br>";
            footer += "<b>Tổng doanh thu : </b>" + txtTongTien.getText() +"<br>";
            if(lbstatus.isVisible())
                footer += "<span style= \" color: red\"><b>Đã Thanh Toán</b>";
            BaoCao bc = new BaoCao();
            bc.baocao(jtDSDVThue,html,footer,"400");
        } catch (Exception ex) {
            Logger.getLogger(frmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
        }
    // TODO add your handling code here:
}//GEN-LAST:event_btnPrintActionPerformed

private void btHuyhoadonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyhoadonActionPerformed
try
{
    if(JOptionPane.showConfirmDialog(this, "Bạn có muốn hủy hoa đơn không ?", "Question",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
    {
        //huy hoa don
        HoaDonController.hoaDon_Delete(HD.getMaHD());
        //cap nhat tinh trang phong
        PhongController.phong_UpdateStatus(MaPhong, "0");
        btHuyhoadon.setEnabled(false);
        btnLapHoaDon.setText("Lập hóa đơn");
        btnLapHoaDon.setEnabled(true);
        lbstatus.setVisible(false);
        JOptionPane.showMessageDialog(this, "Hủy hóa đơn thành công !");
    }
}
catch(Exception e)
{
    JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
   
}
    // TODO add your handling code here:
}//GEN-LAST:event_btHuyhoadonActionPerformed

private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
    try
            {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");//set giao dien
            }
            catch(Exception ex){}
    // TODO add your handling code here:
}//GEN-LAST:event_formComponentShown
///<editor-fold defaultstate="collapsed" desc=" Format_Price ">
    private String Format_Price(String Price)
        {
            if ("0".equals(Price))
            {
                return "0 VNĐ";
            }
            else
                Price = Price.replace(".0", "");
            Price = Price.replace(",", "");
            String tmp = "";
            while (Price.length() > 3)
            {
                tmp = "." + Price.substring(Price.length() - 3) + tmp;
                Price = Price.substring(0, Price.length() - 3);
            }
            tmp = Price + tmp + " VNĐ";
            return tmp;
        }
    //</editor-fold>
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmHoaDon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmHoaDon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmHoaDon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmHoaDon.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmHoaDon().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btHuyhoadon;
    private javax.swing.JButton btnLapHoaDon;
    private javax.swing.JButton btnPrint;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel jltiendvcu;
    private javax.swing.JLabel jltienphongcu;
    private javax.swing.JTable jtDSDVThue;
    private javax.swing.JLabel lbstatus;
    private javax.swing.JTextField txtCMND;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtGioiTinh;
    private javax.swing.JTextField txtHoTen;
    private javax.swing.JTextField txtLoaiPhong;
    private javax.swing.JTextField txtMaKH;
    private javax.swing.JTextField txtMaPhong;
    private javax.swing.JTextField txtNgayDen;
    private javax.swing.JTextField txtNgayDi;
    private javax.swing.JTextField txtNgaySinh;
    private javax.swing.JTextField txtQuocTich;
    private javax.swing.JTextField txtSDT;
    private javax.swing.JTextField txtSoNgay;
    private javax.swing.JTextField txtTenPhong;
    private javax.swing.JTextField txtTienDV;
    private javax.swing.JTextField txtTienDVcu;
    private javax.swing.JTextField txtTienPhong;
    private javax.swing.JTextField txtTongTien;
    private javax.swing.JTextField txttienphongcu;
    // End of variables declaration//GEN-END:variables
}
